// 迭代: 对于源目标(有序的、连续的)依次按逐个抽取的方式来提取数据
// 可迭代: Array、Map、Set、String、TypeArray、arguments、NodeList (都可通过for...of迭代)
// 一、手动实现 Symbol.iterator --- 可迭代对象都存在的方法 
/* function myInterator(iteratorcon) {
    this.index = 0;
    this.length = iteratorcon.length;
    this.iteratorcon = iteratorcon
}
myInterator.prototype.next = function () {
    if (this.index < this.length) {
        return {
            value: this.iteratorcon[this.index++],
            done: false
        }
    } else {
        return {
            value: undefined,
            done: true
        }
    }
}
let iter = new myInterator([1,2,3])
console.log(iter)
console.log(iter.next())
console.log(iter.next())
console.log(iter.next())
console.log(iter.next())
let iter2 = new myInterator('9876');
console.log(iter2)
console.log(iter2.next())
console.log(iter2.next())
console.log(iter2.next())
console.log(iter2.next())
console.log(iter2.next()) */
// 二、实现对象自定义迭代
/* function myObject(obj){
    return {
        ...obj,
        [Symbol.iterator](){
            let map = new Map()
            for(let i in obj){
                map.set(i, obj[i])
            }
            return map.entries()
        }
    }

}
var obj1 = myObject({
    a: 1,
    b: 2, 
    c: 3
})
var iter3 = obj1[Symbol.iterator]()
console.log(iter3.next())
console.log(iter3.next())
console.log(iter3.next())
console.log(iter3.next())
console.log(iter3.next()) */



